package com.lc.question.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.ArrayList;

@Configuration
public class SwaggerConfig {

//    //配置多个分组
//    @Bean
//    public Docket docket1(){
//        return new Docket(DocumentationType.SWAGGER_2)
//                .groupName("A");
//    }

    @Bean
    public Docket docket(Environment environment){
        Profiles profiles = Profiles.of("dev","test");
        //判断是否处于自己设定的环境中‘
        boolean flag = environment.acceptsProfiles(profiles);

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("zz沛")
                .enable(flag)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.zhp.question.controller"))
                .build();

    }

    private ApiInfo apiInfo(){
        //作者信息
        Contact contact = new Contact("zzp沛","https://gitee.com/zzhongpei/question","2459881016@qq.com");

        return new ApiInfo(
                "zz沛的SwaggerAPI文档",
                "问卷调查的各个接口文档及描述",
                "1.0",
                "https://www.baidu.com",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList()
        );

    }

}
